//
//  CarNewsTableViewCell.m
//  小汽车
//
//  Created by 杜远洋 on 14-12-29.
//  Copyright (c) 2014年 蓝欧科技. All rights reserved.
//

#import "CarNewsTableViewCell.h"
#import "Masonry.h"
@implementation CarNewsTableViewCell

- (void)dealloc
{
    [_carImage release];
    [_dates release];
    [_descriptions release];
    [_replyCounts release];
    [_commentImage release];
    [super dealloc];
}
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {

        self.contentView.backgroundColor = [UIColor clearColor];
        
        
        self.carImage  = [[UIImageView alloc] initWithFrame:CGRectMake(10, 10, CELL_WIDTH /5 * 3 , CELL_HEIGHT/7 * 5)];
        
        [self.contentView addSubview:self.carImage];
        [_carImage release];
        
       
        
        self.descriptions = [[UILabel alloc] initWithFrame:CGRectMake(10, self.carImage.frame.size.height + 15, CELL_WIDTH - 20, CELL_HEIGHT - 20 - self.carImage.frame.size.height)];
        [self.descriptions setNumberOfLines:0];
        [self.descriptions setFont:[UIFont systemFontOfSize:16]];
        
       
        [self.contentView addSubview:self.descriptions];
        [_descriptions release];
        
        self.dates = [[UILabel alloc] initWithFrame:CGRectMake(self.carImage.frame.size.width + 15, 10, CELL_WIDTH - self.dates.frame.origin.x - 5, self.carImage.frame.size.height / 2)];
        [self.dates setFont:[UIFont systemFontOfSize:14]];
        
       
        [self.contentView addSubview:self.dates];
        [_dates release];
        
        
        UIImage *image = [UIImage imageNamed:@"message.png"];
        self.commentImage = [[UIImageView alloc] initWithFrame:CGRectMake(self.dates.frame.origin.x , self.dates.frame.origin.y + self.carImage.frame.size.height / 2, 20, 20)];
        
        [_commentImage setImage:image];
        [self.contentView addSubview:_commentImage];
        [_commentImage release];
        
        self.replyCounts = [[UILabel alloc] initWithFrame:CGRectMake(self.dates.frame.origin.x, self.dates.frame.origin.y + self.carImage.frame.size.height / 2, self.dates.frame.size.width, self.dates.frame.size.height / 2)];
        [self.replyCounts setFont:[UIFont systemFontOfSize:14]];
        [self.replyCounts setTextColor:[UIColor colorWithRed:105/255.0f green:105/255.0f blue:105/255.0f alpha:1]];
        [self.contentView addSubview:self.replyCounts];
        [_replyCounts release];
     
    }
    return self;
}
- (void)layoutSubviews
{
    [super layoutSubviews];
     NSUserDefaults *myNight = [NSUserDefaults standardUserDefaults];
    if ([[myNight objectForKey:@"night"] isEqualToString:@"0"]) {
        [self.descriptions setTextColor:[UIColor blackColor]];
    }
    else
    {
        [self.descriptions setTextColor:[UIColor whiteColor]];
        
    }
    
    if ([[myNight objectForKey:@"night"] isEqualToString:@"0"]) {
        [self.dates setTextColor:[UIColor colorWithRed:105/255.0f green:105/255.0f blue:105/255.0f alpha:1]];
    }
    else
    {
        [self.dates setTextColor:[UIColor colorWithRed:65/255.0f green:105/255.0f blue:225/255.0f alpha:1]];
        
    }


    
    
    __block UITableViewCell *weakSelf = self;
    

    [self.carImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(@(weakSelf.frame.size.width * 2 / 75));
        make.top.mas_equalTo(@(weakSelf.frame.size.width * 2 / 75));
        make.size.mas_equalTo(CGSizeMake(weakSelf.frame.size.width / 10 * 3, weakSelf.frame.size.height - weakSelf.frame.size.width * 4 / 75));
    }];

    
    [self.descriptions mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.mas_equalTo(@(weakSelf.frame.size.width / 20 * 7));
        make.top.equalTo(_carImage.mas_top);
        make.height.equalTo(_carImage.mas_height).with.offset(- (weakSelf.frame.size.height - weakSelf.frame.size.width * 4 / 75) / 2);
        make.width.mas_equalTo(@(weakSelf.frame.size.width / 5 * 3));
       
    }];
    
    

    
    [self.dates mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_descriptions.mas_left);
        make.bottom.equalTo(_carImage.mas_bottom);
        make.height.equalTo(_descriptions.mas_height).with.offset(- _descriptions.frame.size.height/2);
        make.width.mas_equalTo(@(weakSelf.frame.size.width / 5 * 2));
    }];
    
    
    
    [self.commentImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(@(weakSelf.frame.size.width / 5 * 4));
        make.top.mas_equalTo(@(weakSelf.frame.size.height - weakSelf.frame.size.width/11));        make.size.mas_equalTo(CGSizeMake(25, 25));
    }];
    
    [self.replyCounts mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_commentImage.mas_right).with.offset(3);
        make.top.equalTo(_dates.mas_top).with.offset(7);
        make.width.mas_equalTo(@(weakSelf.frame.size.width/8));
        make.height.equalTo(_dates.mas_height).with.offset(- weakSelf.frame.size.height/10);
        
    }];

}


- (void)awakeFromNib {
  
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
